package cc.yugu.yhdw.webserver.service.basic;

import cc.yugu.yhdw.common.domain.basic.MobileMessageTemplate;
import cc.yugu.yhdw.common.entity.json.ExtResult;
import cc.yugu.yhdw.common.entity.pagination.Page;
import cc.yugu.yhdw.webserver.persistence.basic.MobileMessageTemplateMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
 * 短信模板业务
 *
 * @Date:Created in 2018/7/3 17:22
 * @Author:
 * @Modified By: zjn 2018/7/3 17:22
 */
@Service
public class MobileMessageTemplateService {

    @Autowired
    MobileMessageTemplateMapper mobileMessageTemplateMapper;
    /**
    * 根据主键和运营商id查询表bas_mobile_message_template 中数据
    *
    * @Param: [agentId, id]
    * @Return: cc.yugu.yhdw.common.domain.basic.MobileMessageTemplate
    * @Author By: zjn 2018/7/3  17:23
    */
    public MobileMessageTemplate find(int agentId, int id) {
        return mobileMessageTemplateMapper.find(agentId, id);
    }
    /**
    * 分页查询
    *
    * @Param: [search]
    * @Return: cc.yugu.yhdw.common.entity.pagination.Page
    * @Author By: zjn 2018/7/3  17:23
    */
    public Page findPage(MobileMessageTemplate search) {
        Page page = search.buildPage();
        page.setTotalItems(mobileMessageTemplateMapper.findPageCount(search));
        search.setBeginIndex(page.getOffset());
        page.setResult(mobileMessageTemplateMapper.findPageResult(search));
        return page;
    }
    /**
    * 更新表
    *
    * @Param: [entity]
    * @Return: cc.yugu.yhdw.common.entity.json.ExtResult
    * @Author By: zjn 2018/7/3  17:23
    */
    public ExtResult update(MobileMessageTemplate entity) {
        if(mobileMessageTemplateMapper.update(entity) == 0) {
            return ExtResult.failResult("操作失败");
        }
        return ExtResult.successResult();
    }
}
